package com.broada.apm.entity;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.broada.apm.cache.L7ModuleCacheManager;
import com.broada.apm.model.L7Module;
import com.broada.apm.model.PerformanceView;
import com.broada.apm.utils.ConfigureProperties;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeName;

/**
 * 系统对应节点信息
 * 
 * @author liss Create By 2014年11月21日 下午4:01:18
 */
@JsonTypeName("service")
public class Service implements Serializable {

	/**
	 * <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;

	private String id;

	/**
	 * 1为节点，2为集群
	 */
	private int nodeType;
	/**
	 * 服务节点名称
	 */
	private String name;
	/**
	 * ip地址
	 */
	private String ip;
	/**
	 * 端口
	 */
	private int port;
	/**
	 * 显示横坐标
	 */
	private int x;
	/**
	 * 显示纵坐标
	 */
	private int y;
	/**
	 * 显示大小
	 */
	private String size;
	/**
	 * 手工指定的协议类型 前端未指定默认显示autoDiscoveryProtocol
	 */
	private int protocol;
	/**
	 * 自动发现的协议类型
	 */
	private int autoDiscoveryProtocol;

	/**
	 * 协议名称
	 */
	private String protocolName;

	/**
	 * 为集群时子节点id
	 */
	private String[] nodeIds;

	private IndicatorItem[] indicatorConfig;

	/**
	 * 自动发现或者手工建立 自动 system 手工 manual
	 */
	private String createBy = "system";

	private Date createdAt;

	private long ipNum;

	private String next;

	private String previous;
	private long tx;
	private long rx;
	private long flow;

	private String lua;
	private PerformanceView performance;
	private int focus;
	private String picUrl;
	private Map<String, Object> perfState;
	private String[] filterIps;

	public String getCreateBy() {
		return createBy;
	}

	public void setCreateBy(String createBy) {
		this.createBy = createBy;
	}

	public void setProtocolName(String protocolName) {
		this.protocolName = protocolName;
	}

	public String getProtocolName() {
		return protocolName;
	}

	public int getProtocol() {
		return protocol;
	}

	public void setProtocol(int protocol) {
		this.protocol = protocol;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public String getSize() {
		return size;
	}

	public void setSize(String size) {
		this.size = size;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public int getNodeType() {
		return nodeType;
	}

	public void setNodeType(int nodeType) {
		this.nodeType = nodeType;
	}

	public String[] getNodeIds() {
		return nodeIds;
	}

	public void setNodeIds(String[] nodeIds) {
		this.nodeIds = nodeIds;
	}

	public IndicatorItem[] getIndicatorConfig() {
		return indicatorConfig;
	}

	public void setIndicatorConfig(IndicatorItem[] indicatorConfig) {
		this.indicatorConfig = indicatorConfig;
	}

	public long getIpNum() {
		return ipNum;
	}

	public void setIpNum(long ipNum) {
		this.ipNum = ipNum;
	}

	public int getAutoDiscoveryProtocol() {
		return autoDiscoveryProtocol;
	}

	public void setAutoDiscoveryProtocol(int autoDiscoveryProtocol) {
		this.autoDiscoveryProtocol = autoDiscoveryProtocol;
	}

	public Date getCreatedAt() {
		return createdAt;
	}

	public void setCreatedAt(Date createdAt) {
		this.createdAt = createdAt;
	}

	public String getNext() {
		return next;
	}

	public void setNext(String next) {
		this.next = next;
	}

	public String getPrevious() {
		return previous;
	}

	public void setPrevious(String previous) {
		this.previous = previous;
	}

	@JsonIgnore
	public String getIconUrl() {
		int _protocol = protocol != 0 ? protocol : autoDiscoveryProtocol;
		L7Module l7module = L7ModuleCacheManager.getInstance().get(String.valueOf(_protocol));
		if (l7module != null)
			return String.format("/%s/resource/%s/%s/logo.png",
					ConfigureProperties.getString("apm.web.17Module.logo.context", "front"), _protocol,
					l7module.getVersion());
		return null;
	}

	public long getTx() {
		return tx;
	}

	public void setTx(long tx) {
		this.tx = tx;
	}

	public long getRx() {
		return rx;
	}

	public void setRx(long rx) {
		this.rx = rx;
	}

	public long getFlow() {
		return flow;
	}

	public void setFlow(long flow) {
		this.flow = flow;
	}

	public String getLua() {
		return lua;
	}

	public void setLua(String lua) {
		this.lua = lua;
	}

	public PerformanceView getPerformance() {
		return performance;
	}

	public void setPerformance(PerformanceView performance) {
		this.performance = performance;
	}

	public int getFocus() {
		return focus;
	}

	public void setFocus(int focus) {
		this.focus = focus;
	}

	public String getPicUrl() {
		return picUrl;
	}

	public void setPicUrl(String picUrl) {
		this.picUrl = picUrl;
	}

	public Map<String, Object> getPerfState() {
		return perfState;
	}

	public void setPerfState(Map<String, Object> perfState) {
		this.perfState = perfState;
	}

	public String[] getFilterIps() {
		return filterIps;
	}

	public void setFilterIps(String[] filterIps) {
		this.filterIps = filterIps;
	}

	@Override
	public String toString() {
		return "Service [id=" + id + ", nodeType=" + nodeType + ", name=" + name + ", ip=" + ip + ", port=" + port
				+ ", x=" + x + ", y=" + y + ", size=" + size + ", protocol=" + protocol + ", autoDiscoveryProtocol="
				+ autoDiscoveryProtocol + ", protocolName=" + protocolName + ", nodeIds=" + Arrays.toString(nodeIds)
				+ ", createBy=" + createBy + ", createdAt=" + createdAt + ", ipNum=" + ipNum + "]";
	}

	public Service() {
		
	}
	
	public Service(String id, String name, String ip, int port, String protocolName, PerformanceView perf, int focus, Map<String, Object> perfState, int protocol, int autoDiscoveryProtocol) {
		this.id = id;
		this.name = name;
		this.ip = ip;
		this.port = port;
		this.protocolName = protocolName;
		this.performance = perf;
		this.focus = focus;
		this.perfState = perfState;
		this.protocol = protocol;
		this.autoDiscoveryProtocol = autoDiscoveryProtocol;
	}
}
